package cn.lcsjsxy.yxc.servlet.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet(value = "/servletA")
public class ServletA extends HttpServlet {
    public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("A");
        //重定向到ServletB
        /*
         * 1.相对路径写法
         *      和前端的相对路径规则一致
         * 2.绝对路径写法
         *      http://localhost:8080/
         * */
        resp.sendRedirect("/servletB");

        /*请求转发到ServletB
        * 1.相对路径写法一致
        *       http://localhost:8080/demo4/servletA
        * 2.绝对路径
        *       请求转发的绝对路径不需要添加上下文
        *       请求转发的/代表的路径是  http://localhost:8080/demo4/
        * */
//        req.getRequestDispatcher("/servletB").forward(req, resp);
    }
}
